package demo0526;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Set<Emp> empSet = new HashSet<>();
        TestSet testSet = new TestSet();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            TestSet.menu();
            int choice = scanner.nextInt();
            scanner.nextLine();

            switch (choice) {
                case 0:
                    System.out.println("退出系统，再见！");
                    scanner.close();
                    return;
                case 1:
                    System.out.println("请输入员工编号：");
                    String number = scanner.nextLine();
                    System.out.println("请输入员工姓名：");
                    String name = scanner.nextLine();
                    System.out.println("请输入员工年龄：");
                    int age = scanner.nextInt();
                    scanner.nextLine(); // 消耗换行符
                    Emp newEmp = new Emp(number, name, age);
                    testSet.addEmp(empSet, newEmp);
                    System.out.println("添加成功");
                    break;
                case 2:
                    System.out.println("所有员工信息：");
                    testSet.findAllEmp(empSet);
                    break;
                case 3:
                    System.out.println("请输入要查询的员工姓名：");
                    String queryName = scanner.nextLine();
                    testSet.findEmpName(empSet, queryName);
                    break;
                case 4:
                    System.out.println("请输入要删除的员工编号：");
                    String deleteNumber = scanner.nextLine();
                    testSet.deleteEmpNumber(empSet, deleteNumber);
                    break;
                case 5:
                    System.out.println("请输入要查询的员工编号：");
                    String findNumber = scanner.nextLine();
                    Emp foundEmp = testSet.findEmpNumber(empSet, findNumber);
                    if (foundEmp != null) {
                        System.out.println("找到员工：" + foundEmp);
                    } else {
                        System.out.println("未找到该员工");
                    }
                    break;
                case 6:
                    System.out.println("请输入要修改的员工编号：");
                    String updateNumber = scanner.nextLine();
                    Emp oldEmp = testSet.findEmpNumber(empSet, updateNumber);
                    if (oldEmp != null) {
                        System.out.println("请输入新的年龄：");
                        int newAge = scanner.nextInt();
                        scanner.nextLine(); // 消耗换行符
                        Emp updatedEmp = new Emp(updateNumber, oldEmp.getName(), newAge);
                        testSet.updateEmpAge(empSet, updatedEmp);
                        System.out.println("修改成功");
                    } else {
                        System.out.println("未找到该员工");
                    }
                    break;
                default:
                    System.out.println("无效的选择，请重新输入");
            }
        }
    }
}
